home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 352_01.zip / STRPPFNS.CPP < prev    next >
C/C++ Source or Header  |  1993-04-10  |  842b  |  35 lines

  1. // STRPPFNS.CPP - contains String::findstr()
  2. //        this module searches one char string for another contained within
  3. //        similar to strstr() but obeys String::caseSens
  4. //        and returns offset rather than ptr.
  5. //
  6. // NOTE: routine declared static in class {}. No 'this' ptr.        
  7. //
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <alloc.h>
  11. #include <iostream.h>
  12. #include <ctype.h>
  13.  
  14. #include "dblib.h"
  15.  
  16. int String::findstr ( char *a, int na, char *b )
  17.     // search for string b in string a. return offset of pattern
  18.     {
  19.     _NORMALIZE (a, char*);
  20.     _NORMALIZE (b, char*);
  21.     
  22.     int nb = strlen (b);
  23.     if (! ( a==NULL || b== NULL || nb== 0 ) )
  24.         {
  25.         int limit = na-nb+1;
  26.     
  27.         for ( int i=0; i<limit; ++i )
  28.             {
  29.             if ( 0==String::memcmp(a+i, b, nb) ) return i;
  30.             }
  31.         }
  32.     return -1;    // not found.
  33.     };            // end String::findstr()
  34.  
  35.